import Vue from 'vue';
import VueRouter from 'vue-router';
import HomeView from '../views/Home.vue';

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        name: '洞健，一起洞察健康',
        component: HomeView,
    },
    {
        path: '/HotList',
        name: '热榜',
        component: () =>
            import(/* webpackChunkName: "HotList" */ '../views/HotList.vue'),
    },
    {
        path: '/Zhuanti',
        name: '专题',
        component: () =>
            import(/* webpackChunkName: "Zhuanti" */ '../views/Zhuanti.vue'),
    },
    {
        path: '/Actives',
        name: '活动',
        component: () =>
            import(/* webpackChunkName: "Actives" */ '../views/Actives.vue'),
    },
    {
        path: '/ZhuantiDetail',
        name: '专题详情',
        component: () =>
            import(
                /* webpackChunkName: "ZhuantiDetail" */
                '../views/ZhuantiDetail.vue'
            ),
    },
    {
        path: '/ActiveDetial',
        name: '活动详情',
        component: () =>
            import(
                /* webpackChunkName: "ActiveDetial" */
                '../views/ActiveDetial.vue'
            ),
    },

    {
        path: '/Detial',
        name: '详情',
        component: () =>
            import(/* webpackChunkName: "Search" */ '../views/Detial.vue'),
    },
    {
        path: '/Search',
        name: '搜索',
        component: () =>
            import(/* webpackChunkName: "Search" */ '../views/Search.vue'),
    },

    {
        path: '/Help',
        name: '帮助',
        component: () =>
            import(/* webpackChunkName: "Help" */ '../views/Help/index.vue'),
        children: [
            {
                path: 'About',
                name: '关于我们',
                component: () =>
                    import(
                        /* webpackChunkName: "About" */
                        '../views/Help/About.vue'
                    ),
            },
            {
                path: 'contact',
                name: '联系我们',
                component: () =>
                    import(
                        /* webpackChunkName: "contact" */
                        '../views/Help/Content.vue'
                    ),
            },
            {
                path: 'Company',
                name: '企业合作',
                component: () =>
                    import(
                        /* webpackChunkName: "Company" */
                        '../views/Help/Company.vue'
                    ),
            },
            {
                path: 'Links',
                name: '友情链接',
                component: () =>
                    import(
                        /* webpackChunkName: "Links" */
                        '../views/Help/Links.vue'
                    ),
            },
            {
                path: 'Xieyi',
                name: '用户协议',
                component: () =>
                    import(
                        /* webpackChunkName: "Xieyi" */
                        '../views/Help/Xieyi.vue'
                    ),
            },
            {
                path: 'Version',
                name: '版本说明',
                component: () =>
                    import(
                        /* webpackChunkName: "Version" */
                        '../views/Help/Version.vue'
                    ),
            },
            {
                path: 'Feedback',
                name: '意见反馈',
                component: () =>
                    import(
                        /* webpackChunkName: "Feedback" */
                        '../views/Help/Feedback.vue'
                    ),
            },
            {
                path: 'Joinus',
                name: '加入我们',
                component: () =>
                    import(
                        /* webpackChunkName: "Joinus" */
                        '../views/Help/Joinus.vue'
                    ),
            },
        ],
    },
];

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
});

// router.beforeEach(() => {
//     // document.body.scrollTop = 0;
//     // window.pageYOffset = 0;
//     // document.documentElement.scrollTop = 0;
// });

//导航后置守卫，可以在确定导航到目标页面时再更改title
router.afterEach((to) => {
    if (to.path != '/') {
        window.document.title = '洞健-' + to.name;
    } else {
        window.document.title = to.name;
    }

    document.body.scrollTop = 0;
    window.pageYOffset = 0;
    document.documentElement.scrollTop = 0;
});

export default router;
